<template>
  <div>
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>角色管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <hr style="border: 1px solid #F2F6FC;">
    <div class="rolelist">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="roleId" label="角色id">
        </el-table-column>
        <el-table-column prop="roleName" label="角色名">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleView(scope.row)" type="text" size="small">详情</el-button>
            <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-drawer :visible.sync="describleshow" direction="ttb" size="50%" :before-close="handleClose"
      :modal-append-to-body="false">
      <el-descriptions title="角色信息" border v-if="permlist">
        <el-descriptions-item label="角色id">{{ this.roleId }}</el-descriptions-item>
        <el-descriptions-item label="角色名">{{ this.roleName }}</el-descriptions-item>
        <el-descriptions-item label="拥有权限">{{ this.permlist}}</el-descriptions-item>
      </el-descriptions>
    </el-drawer>
  </div>
</template>

<script>
import { getAllRole, getPermListByRoleId } from '@/api/api'
export default {
  data () {
    return {
      tableData: [],
      roleId: null,
      roleName: '',
      permlist: '111',
      describleshow: false
    }
  },
  methods: {
    handleClick (row) {
      const role = JSON.stringify(row)
      this.$router.push({
        path: '/role/assinPerm',
        query: { role }
      })
    },
    handleView (row) {
      this.roleId = row.roleId
      this.roleName = row.roleName
      getPermListByRoleId(row.roleId).then(res => {
        // console.log(res.data)
        this.permlist = res.data.data.join(', ')
      })
      this.describleshow = true
    },
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
  },
  mounted () {
    getAllRole().then(res => {
      // console.log(res.data)
      this.tableData = res.data.data
    })
  }
}
</script>

<style lang="scss" scoped>
.rolelist {
  margin: 20px 0px 0px 0px;
}
</style>
